home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / pao / pvs_pvd / src / fontfile.c < prev    next >
Text File  |  1994-06-01  |  6KB  |  198 lines

  1. /* << HighC V1.7 >> [FM-TOWNS] **********************************************
  2. *
  3. *    フォントファイル処理
  4. *    ----------------------------------------------------------------------
  5. *    Programmed by Y.Hirata ( NIFTY-ID: NAB03321  パオパオ )
  6. *
  7. *    NOTE: TAB=4
  8. ****************************************************************************/
  9.  
  10. #include <ctype.h>        /*  islower        */
  11. #include <string.h>        /*  str*,mem*    */
  12. #include "egbtxt.h"        /*  FNT,EGB        */
  13.  
  14. #define    TRUE                1
  15. #define    FALSE                0
  16.  
  17. const char    *FONT1[] = {    "MINN",    "GOTH",    "KYOU",    "MARU",    "MOUH"    } ;
  18. const char    *FONTS[] = {    "24",    "32",    "48",    "60"    } ;
  19. const char    *FONT2[] = {    "",        "HH",    "HK",    "QH",    "QK"    } ;
  20. const int    FONTSZ[] = {    72,        128,    288,    480        } ;
  21. const char    *TYPENAME[] = {    "FONT    ",
  22.                             "FONT1   ",
  23.                             "FONT2   "
  24. } ;
  25.  
  26. char    FontPath[NFONT2][_MAX_PATH] ;            /*  フォントファイルパス            */
  27. char    FontData[64/8*60] ;                        /*  フォント読み込み用        */
  28. int        FontType ;                                /*  フォントファイル種別        */
  29. int        FontNo ;                                /*  フォント種別            */
  30. int        FontDots=24 ;                            /*  フォントサイズ(dots)        */
  31. int        FontSize=72 ;                            /*  フォントサイズ(byte)        */
  32. int        FontSizeNo=0 ;                            /*  フォントサイズNo.            */
  33. FILE    *FontFp[NFONT2] = { NULL } ;            /*  フォントファイルポインタ        */
  34.  
  35. void strupper( char *str )
  36. /*===========================================================================
  37. *    文字列中の小文字を大文字に変換
  38. ===========================================================================*/
  39. {
  40.     register int    cnt ;
  41.  
  42.     for ( cnt=0; cnt<strlen( str ); cnt++ ) {    /*  小文字 -> 大文字    */
  43.         if ( iskanji( str[cnt] ) ) {
  44.             cnt++ ;
  45.         } else {
  46.             if ( islower( str[cnt] ) ) str[cnt] -= ' ' ;
  47.         }
  48.     }
  49. }
  50.  
  51. void makeFontPath( void )
  52. /*===========================================================================
  53. *    フォントファイルのフルパスを作成
  54. ===========================================================================*/
  55. {
  56.     register int    cp, term=FALSE ;
  57.     int        len ;
  58.     char    *path ;
  59.  
  60.     strcpy( FontPath[0],"" ) ;
  61.     if ( (path=getenv( "FNT" )) != NULL ) {        /*  環境変数'FNT='        */
  62.         len = strlen( path ) ;
  63.         if ( path[len-1] == '\\' ) {
  64.             for ( cp=0; cp<len; cp++ ) {
  65.                 if ( iskanji( path[cp] ) ) {        /*  漢字    */
  66.                     term = FALSE ;
  67.                     ++cp ;
  68.                 } else {
  69.                     term = TRUE ;
  70.                 }
  71.             }
  72.         }
  73.         strcpy( FontPath[0],path ) ;
  74.         strupper( FontPath[0] ) ;
  75.         if ( !term ) {
  76.             FontPath[0][len]   = '\\' ;            /*  '\'の追加            */
  77.             FontPath[0][len+1] = '\0' ;
  78.         }
  79.     }
  80.     strcat( FontPath[0],FONT1[FontNo] )    ;
  81.     strcat( FontPath[0],FONTS[FontSizeNo] )    ;
  82.     for ( cp=1; cp<NFONT2; cp++ ) {
  83.         strcpy( FontPath[cp],FontPath[0] ) ;
  84.         strcat( FontPath[cp],FONT2[cp] ) ;
  85.     }
  86.     strcat( FontPath[0],FONT2[0] ) ;
  87.     for ( cp=0; cp<NFONT2; cp++ ) strcat( FontPath[cp],".FNT" ) ;
  88. }
  89.  
  90. int chkFontFile( void )
  91. /*===========================================================================
  92. *    フォントファイル種別のチェック
  93. ===========================================================================*/
  94. {
  95.     register int    cnt ;
  96.     char    type[8] ;
  97.  
  98.     if ( FontFp[0] == NULL ) {
  99.         FontType = -1 ;
  100.         return 1 ;
  101.     }
  102.     rewind( FontFp[0] ) ;
  103.     if ( fread( type,1,8,FontFp[0] ) == 8 ) {
  104.         for ( cnt=0; cnt<NTYPE; cnt++ ) {
  105.             if ( !memcmp( type,TYPENAME[cnt],8 ) ) {
  106.                 FontType = cnt ;
  107.                 return 0 ;
  108.             }
  109.         }
  110.     }
  111.     FontType = -1 ;
  112.     return 1 ;
  113. }
  114.  
  115. int getFontOffset( int *sjis )
  116. /*===========================================================================
  117. *    フォントファイル中のオフセット
  118. ===========================================================================*/
  119. {
  120.     char    h, l ;
  121.     int        size=FontSize ;
  122.     int        hsize=16 ;
  123.  
  124.     *sjis = FNT_sjisToJis( *sjis ) ;
  125.     l = *sjis & 0xFF ;
  126.     if ( l < 0x21 || l > 0x7E ) return -1 ;
  127.     h = (unsigned short int)*sjis >> 8 ;
  128.     if ( h < 0x21 || h > 0x74 ) return -1 ;
  129.     switch ( FontType ) {
  130.     case 0:
  131.     case 1:    size += 2 ;        break ;
  132.     case 2:    hsize += ( size * 128 ) ;
  133.     }
  134.     return ( ( (h-0x21) * 94 + (l-0x21) ) * size + hsize ) ;
  135. }
  136.  
  137. int loadFont( FILE *fp,int code,int kanji )
  138. /*===========================================================================
  139. *    フォントの読み込み
  140. ===========================================================================*/
  141. {
  142.     register int    ch, size=FontSize ;
  143.  
  144.     if ( FontType == 0 || FontType == 1 ) {
  145.         ch = fgetc( fp ) << 8 ;
  146.         ch |= fgetc( fp ) ;
  147.         if ( feof( fp ) ) return 1 ;
  148.         if ( ch != code ) return 2 ;
  149.     } else {
  150.         if ( !kanji ) size /= 2 ;
  151.     }
  152.     if ( fread( FontData,1,size,fp ) < size ) return 3 ;
  153.     return 0 ;
  154. }
  155.  
  156. int fontOpen( int fno,int dots )
  157. /*===========================================================================
  158. *    フォントファイルオープン
  159. *    < RET >    : 設定条件に誤りがなければ 0, 誤りならば 1 を返す.
  160. ===========================================================================*/
  161. {
  162.     int        cnt ;
  163.  
  164.     if ( fno < 0 || fno > F_MOUH ) return 1 ;
  165.     for ( cnt=0; cnt<NSIZE; cnt++ ) {
  166.         if ( atoi( FONTS[cnt] ) == dots ) break;
  167.     }
  168.     if ( cnt >= NSIZE ) return 1 ;
  169.     FontSizeNo = cnt ;                            /*  フォントサイズ種別        */
  170.     FontNo     = fno ;                            /*  フォント種別            */
  171.     FontDots   = dots ;                            /*  ドットサイズ            */
  172.     FontSize = FONTSZ[FontSizeNo] ;                /*  フォントデータサイズ        */
  173.     makeFontPath() ;                            /*  フォントファイルのパス作成    */
  174.     for ( cnt=0; cnt<NFONT2; cnt++ ) {
  175.         if ( FontFp[cnt] != NULL ) fclose( FontFp[cnt] ) ;
  176.         FontFp[cnt] = fopen( FontPath[cnt],"rb" ) ;
  177.     }
  178.     chkFontFile() ;                                /*  フォントファイルの種別チェック    */
  179.     return 0 ;
  180. }
  181.  
  182. void fontClose( void )
  183. /*===========================================================================
  184. *    フォントファイルクローズ
  185. ===========================================================================*/
  186. {
  187.     int        cnt ;
  188.  
  189.     for ( cnt=0; cnt<NFONT2; cnt++ )
  190.         if ( FontFp[cnt] != NULL ) fclose( FontFp[cnt] ) ;
  191. }
  192.  
  193. /*    HISTORY
  194. -----------------------------------------------------------------------------
  195. *    1991.04.13 : CREATE
  196. *    1993.08.09 : remake
  197. ---------------------------------------------------------------------------*/
  198.